package common.util;

import common.sql.DataSource;
import common.sql.Operator;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Objects;

/**
 * @author: Han
 * @date: 2018/8/21 9:17
 * @dscription: 文件操作类
 */
public class FileOperator {
    public static void main(String... args) {
        readDetailList();
    }

    private static void readDetailList() {
        Operator operator = Operator.getInstance();
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(
                    new FileInputStream("C:\\Users\\Han\\Desktop\\ActivityOfLeader.txt"), "gbk"));
            String line;
            while ((line = reader.readLine()) != null) {
                if (!line.startsWith("http")) {
                    continue;
                }
                String[] ss = line.split(" ");
                operator.insertDetailList(ss[0], ss[1]);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                Objects.requireNonNull(reader).close();
            } catch (IOException e) {
                e.printStackTrace();
            }
            DataSource.closePool();
        }
    }

    public static String readTest() {
        BufferedReader reader = null;
        StringBuilder lines = new StringBuilder();
        try {
            reader = new BufferedReader(new InputStreamReader(
                    new FileInputStream("C:\\Users\\Han\\Desktop\\a.txt"), "gbk"));
            String line;
            while ((line = reader.readLine()) != null) {
                lines.append(line).append("\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                Objects.requireNonNull(reader).close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        return lines.toString();
    }
}
